<?php

class HTech_Form extends Zend_Form
{
    /*
     * _primary must be initialized in the subclases
     */
    protected $_primary;
    protected $_request; 
    protected $_id;    
    protected $_db;
    protected $_conf;
    
    public function __construct($options = null) 
    {   
        parent::__construct($options);
        parent::setAttrib('method', self::METHOD_POST); 
        $this->_request = Zend_Controller_Front::getInstance()->getRequest();
        $this->_id = $this->_request->getPost($this->_primary);
        $this->_db = Zend_Registry::get('db');
        $this->_conf = Zend_Registry::get('HT_Config');
    }
    
    public function getValues()
    {
        return parent::getValues() + $this->getXtraValues();
        /*
        array(
            'LastEditUserId' => Zend_Auth::getInstance()->getIdentity()->UserId,
            'LastEditDate'   => date('Y-m-d H:i:s'));
         * 
         */
    }
    
    public function getXtraValues()
    {
        return array(
            'LastEditUserId' => Zend_Auth::getInstance()->getIdentity()->UserId,
            'LastEditDate'   => date('Y-m-d H:i:s'));
    }
    
    public function translate($value)
    {     
        return $this->getTranslator()->translate($value);
    }
    
    public function deny($e,$url='default/auth/deny')
    {
        $flashMessenger = new Zend_Controller_Action_Helper_FlashMessenger();
        $redirector = new Zend_Controller_Action_Helper_Redirector();
        $flashMessenger->addMessage($e->getMessage());
        $redirector->gotoUrlAndExit($url);
    }
}